const gulp = require("gulp");
const connect = require("gulp-connect");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");

gulp.task("html",done=>{
    gulp.src("*.html")
    .pipe(gulp.dest("dist"))
    .pipe(connect.reload());
    done();
});
gulp.task("copyHtml",done=>{
    gulp.src("html/*.html")
    .pipe(gulp.dest("dist/html"))
    .pipe(connect.reload());
    done();
});
gulp.task("sass",done=>{
    gulp.src("sass/*.scss")
    .pipe(sourcemaps.init())
    .pipe(sass({
        "outputStyle":"compressed"
    }))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest("dist/css"))
    .pipe(connect.reload());
    done();
});
gulp.task("copyJs",done=>{
    gulp.src("js/*.js").pipe(gulp.dest("dist/js"))
    .pipe(connect.reload());
    done();
}); 
gulp.task("copyCss",done=>{
    gulp.src("css/*.css").pipe(gulp.dest("dist/css"))
    .pipe(connect.reload());
    done();
}); 
gulp.task("copyImg",(done)=>{
    gulp.src("img/**").pipe(gulp.dest("dist/img"))
    .pipe(connect.reload());
    done();
});

gulp.task("server",done=>{
    connect.server({
        root:"dist",
        livereload:true
    })
    done();
});
gulp.task("watch",done=>{
    gulp.watch("*.html",gulp.series("html"));
    gulp.watch("sass/*.scss",gulp.series("sass"));
    gulp.watch("css/*.css",gulp.series("copyCss"));
    gulp.watch("js/*.js",gulp.series("copyJs"));
    gulp.watch("html/*.html",gulp.series("copyHtml"));
    done();
});
gulp.task("build",gulp.parallel("html","copyHtml","sass","copyJs","copyCss","copyImg"));
gulp.task("default",gulp.series("build","watch","server"));